﻿using HuiZe.education.Common;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace HuiZe.education.Resource.Controls
{
    /// <summary>
    /// PageManager.xaml 的交互逻辑
    /// </summary>
    public partial class ResourceCenter : UserControl
    {

        public string NomalImage { get; set; }
        public string Labtext { get; set; }
        public string Id { get; set; }
        public bool IsSelectd { get; set; } = false;

        public string alreadyShareUrl = "../Images/New/icon-collect2.png";
        public string noShareUrl = "../Images/New/icon-collect.png";
        public bool IsShare { get; set; } = false;
        public ResourceCenter()
        {
            InitializeComponent();
            Loaded += PageManager_Loaded;
        }
        private void PageManager_Loaded(object sender, RoutedEventArgs e)
        {
            Image image = new Image(); 
            image.Source = new BitmapImage(new Uri(NomalImage, UriKind.Absolute));
            image.Stretch = Stretch.Fill;
            BookImg.Source = image.Source;
            BookName.Content = Labtext;
            if (!IsShare)
            {
                shareImg.Source = new BitmapImage(new Uri(noShareUrl, UriKind.RelativeOrAbsolute));
            }
            else
            {
                shareImg.Source = new BitmapImage(new Uri(alreadyShareUrl, UriKind.RelativeOrAbsolute));
            }
            
            
        }

         private  void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            CustomRadioButton customRadioButton = sender as CustomRadioButton;
            //CurrentIndex = customRadioButton.Index;
        }

        private void UserControl_FocusableChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
        }

        private void UserControl_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void BookImg_MouseDown(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement __do = this.Parent as FrameworkElement;
            var WrapParent = this.Parent  as WrapPanel;

            //while (__do != null)
            //{
            //    __do = __do.Parent as FrameworkElement;
            //    if (__do.Parent.ToString() == "WrapPanel")
            //    {
            //        //AttendClassViewModel Context = __do.DataContext as ;
            //        var ParentView = __do.Parent;
            //        //ParentView.Update0();
            //        break;
            //    }
            //}

            if(WrapParent!=null)
            { 

                foreach (var control in WrapParent.Children)
            {
                if (control == this)
                {
                    ImgBorder.BorderBrush = Brushes.Red;
                    CommonMethods.nowId = Id;
                    IsSelectd = true;
                    //Window parentWindow = Window.GetWindow(this);
                }
                else 
                {
                    var Book = control as ResourceCenter;
                    Book.ImgBorder.BorderBrush = Brushes.Gray;
                    IsSelectd = false; ;

                }

            }
            }
        }
    }
}
